package eerbaar.v2.menu;

import eerbaar.v2.app.mouse.IMouseListener;
import eerbaar.v2.app.mouse.MouseEvent2;

public class MenuMouse implements IMouseListener {

    public MenuMouse() {
        //
    }

    @Override
    public void mouseClicked(MouseEvent2 e) {

        MenuItem m = new Menu().findMenu(e.getPoint());

        if (m != null) {
            e.stop();
            m.execute();
            m.toggleRunning();
        }
    }

    @Override
    public void mouseExited() {
        //
    }

    @Override
    public void mouseMoved(MouseEvent2 e) {

        PetMenuProvider p = PetMenuProvider.getInstance();

        MenuItem[] items = p.getMenuItems();
        for (MenuItem i : items) {
            i.setMouseOver(false);
        }

        MenuItem m = new Menu().findMenu(e.getPoint());
        if (m != null) {
            m.setMouseOver(true);
        }
    }

}
